home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / WN_GPWOR.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  6KB  |  144 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1989 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_gpword - get text password from window NO ECHO TEXT ENTRY!!!
  7. **
  8. ** Copyright (c) 1989 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "winboss.h"                    /* standard stuff */
  14.  
  15. /*
  16. *************
  17. * wn_gpword *
  18. *************
  19. */
  20.  
  21. /*
  22. ** wn_gpword(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  23. **
  24. **    int        fun - fucntion code (SET || XEQ)
  25. **    (WIFORM)   frm - form pointer  (actual || NFRM)
  26. **    int        fld - field # in form (actual || NFLD)
  27. **    (WINDOWPTR) wn - window pointer
  28. **    int        row - row in window where data input begins
  29. **    int        col - col in window where data input begins
  30. **    (char *) prmpt - field promt (call with NSTR for none)
  31. **    unsigned atrib - field (not prompt) atributes 
  32. **    char      fill - field fill character
  33. **    int     fwidth - width of mask (maximum # of digits is MAXSTR)
  34. **    (char *) ubuff - pointer to char array of fwidth+2 bytes for editing 
  35. **    (char *)hlpmsg - pointer to help message (call with NSTR for none)
  36. **    (char *)errmsg - pointer to err message (call with NSTR) for none)
  37. **
  38. ** RETURNS:
  39. **
  40. **    UBUFF with text data via pointer.
  41. **
  42. **    NULL if error, else the non zero value returned from wn_input.
  43. **
  44. ** NOTES:
  45. **
  46. **  FUN -   fun can only be SET for form setup, or XEQ for immediate
  47. **          execution.  When called with SET, valid arguements for both
  48. **          "frm" and "fld" must be specfied.  frm is the field pointer
  49. **          returned from frmopn(), and fld is the field sequence number
  50. **          in the form for this field.  When called with XEQ frm must
  51. **          be NFRM and fld must NFLD.
  52. **
  53. **  UBUFF - Editing buffer.  Must be of sufficent size to hold the
  54. **          data as it is entered.  Typical value is the length
  55. **          of the mask + 2 bytes (strlen(mask)+2).
  56. **
  57. **          On entry, the first byte of ubuff should be 
  58. **          a null, otherwise wn_input assumes there is valid
  59. **          data there and will enter edit mode.  This can be 
  60. **          handy if there is a need for prefilled but editable
  61. **          fields.  In actual pratice, wn_input uses this
  62. **          buffer for both initial character data entry and
  63. **          subsequent editing.  
  64. **
  65. **          On return, ubuff contains the actual data entered in
  66. **          character format with fill and mask characters as
  67. **          spaces (e.g. "This is a line of text ").
  68. **
  69. **  Calls wn_input to perform data entry.
  70. **
  71. **  No validation is performed.
  72. */
  73.  
  74. /*
  75. *************
  76. * wn_gpword *
  77. *************
  78. */
  79.  
  80. wn_gpword(fun,frm,fld,wn,row,col,prmpt,atrib,fill,fwidth,ubuff,hlpmsg,errmsg)
  81. int fun;                                /* SET or XEQ */
  82. WIFORM frm;                             /* form pointer or NFRM */
  83. int fld;                                /* field number or NFLD */
  84. WINDOWPTR wn;                           /* window to use */
  85. int row, col;                           /* position of input field */
  86. char *prmpt;                            /* prompt string */
  87. unsigned atrib;                         /* data entry atribute */
  88. char fill;                              /* fill char */
  89. int fwidth;                             /* field width */
  90. char *ubuff;                            /* returns "text" */
  91. char *hlpmsg, *errmsg;                  /* help & error messages */
  92. {
  93. char *mask;                             /* mask buffer */
  94. char *p;                                /* scratch */
  95. int i;                                  /* scratch */
  96. int rv;                                 /* return value */
  97.  
  98.   if(fun != SET && fun != XEQ)          /* saftey check */
  99.     return(NULL);
  100.  
  101.   if(fun == SET) {                      /* set up */
  102.     if(frm[fld]->pself != (char *)frm[fld])
  103.       wns_ierr("wn_gpword");            /* die if memory is mangled */
  104.     frm[fld]->wn = wn;                  /* set window */
  105.     frm[fld]->row = row;                /* set row */
  106.     frm[fld]->col = col;                /* set col */
  107.     frm[fld]->prmpt = prmpt;            /* set prompt */
  108.     frm[fld]->atrib = atrib;            /* set attribute */
  109.     frm[fld]->fill = fill;              /* set fill character */
  110.     frm[fld]->fcode = GPWORD;           /* function code */
  111.     frm[fld]->v1.vi = fwidth;           /* fwidth */
  112.     frm[fld]->v2.vcp = ubuff;           /* &ubuff */
  113.     frm[fld]->v3.vcp = hlpmsg;          /* &hlpmsg */
  114.     frm[fld]->v4.vcp = errmsg;          /* &errmsg */
  115.     return(TRUE);
  116.   }
  117.  
  118.   if(fwidth >= MAXSTR) {                /* dont allow foolishness */
  119.     *ubuff = NUL;                       /* indicate error */
  120.     return(NULL);                       /* and return */
  121.   }
  122.   mask = malloc(fwidth+2);              /* fetch some memory */
  123.   if(!mask) {                           /* allocation fail ?? */
  124.     *ubuff = NUL;                       /* terminate string */
  125.     return(NULL);                       /* say things went bad */
  126.   }
  127.   p = mask;                             /* temp pointer */
  128.   for(i=0; i<fwidth; i++) {             /* set up mask */
  129.     *p = 'X';                           /* NOECHO TEXT */
  130.     p++;                                /* bump pointer */
  131.     *p = NUL;                           /* terminate string */
  132.   }
  133.   if(!(rv=wn_input(wn,row,col,prmpt,mask,fill,atrib,ubuff,hlpmsg))) {
  134.     *ubuff= NUL;                        /* indicate error */
  135.     free(mask);                         /* free memory */
  136.     return(NULL);                       /* indicate error */
  137.   }
  138.   free(mask);                           /* free memory */
  139.   if(wni_frmflg) return(TRUE);          /* wn_frmget in progress */
  140.   return(rv);                           /* all done */
  141. }
  142.  
  143. /* End */
  144.